home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 001-010 / amok01 / ctrlintuition / controlintuition.mod < prev    next >
Text File  |  1993-11-04  |  8KB  |  207 lines

  1. (*---------------------------------------------------------------------------
  2.    :Program.    ControlIntuition
  3.    :Author.     Fridtjof Björn Siebert
  4.    :Address.    Nobileweg 67, D-7-Stgt-40
  5.    :Phone.      (0)711/822509
  6.    :Shortcut.   [fbs]
  7.    :Version.    1.0
  8.    :Date.       31-May-88
  9.    :Copyright.  PD
  10.    :Language.   MODULA-II
  11.    :Translator. M2Amiga
  12.    :Contents.   Prozeduren, die es ermöglichen, Intuition aus und an zu
  13.    :Contents.   schalten. Damit hat man volle Kontrolle Über den Amiga.
  14.    :Remark.     I didn't believe this could be so easy !
  15. ---------------------------------------------------------------------------*)
  16.  
  17. IMPLEMENTATION MODULE ControlIntuition;
  18.  
  19. FROM SYSTEM      IMPORT ADR, ADDRESS, SETREG, REG, SHIFT, LONGSET, CAST;
  20. FROM Arts        IMPORT Assert,TermProcedure;
  21.  
  22. FROM Dos         IMPORT Delay;
  23. FROM Exec        IMPORT MsgPortPtr, IOStdReq, Interrupt, MemEntry, Forbid,
  24.                         Permit, IOStdReqPtr, OpenDevice, CloseDevice, DoIO,
  25.                         Disable, Enable;
  26. FROM ExecSupport IMPORT CreatePort, DeletePort, CreateStdIO, DeleteStdIO;
  27. FROM Input       IMPORT inputName, addHandler, remHandler;
  28. FROM InputEvent  IMPORT InputEvent, InputEventPtr, Class, lButton, mButton,
  29.                         rButton;
  30. FROM Timer IMPORT TimeVal;
  31.  
  32. (*----------------  Variablen aus Definition:  ------------------------------
  33.  
  34. VAR
  35.   DisableIntuiCount: CARDINAL;
  36.   (* Zähler für verschachtelte Aufrufe von DisableIntuition *)
  37.  
  38.   MouseX, MouseY: LONGINT;
  39.   (* Mouse Position. Wird währen Intuition ausgeschaltet ist, verändert.   *)
  40.   (* Es wird kein Rand getestet. Es kann also theoretisch zu einem Über-   *)
  41.   (* kommen, dazu muß die Maus jedoch über 500km in eine Richtung bewegt   *)
  42.   (* werden, ist also relativ unwahrscheinlich.                            *)
  43.  
  44.   RightButton, LeftButton, MiddleButton: TimeVal;
  45.   (* Die Zeit, zu der der letzte Mouse-Event des jeweiligen Buttons kam.   *)
  46.   (* MiddleButton konnte ich mangels Hardware nicht testen.                *)
  47.  
  48.   RightButtonRel, LeftButtonRel, MiddleButtonRel: TimeVal;
  49.   (* Wie oben, nur Buttons losgelassen                                     *)
  50.  
  51.   LastRawKey: CARDINAL;
  52.   LastRawKeyTime: TimeVal;
  53.   (* Der letzte RawKey und wann er gedrückt wurde                          *)
  54.  
  55.   LastTime: TimeVal;
  56.   (* Zeit des letzten Events                                               *)
  57.  
  58. ---------------------------------------------------------------------------*)
  59.  
  60. (*--------------------  interne Variablen:  -------------------------------*)
  61.  
  62. VAR
  63.   InputDevPort: MsgPortPtr;       (* My MessagePort *)
  64.   InputRequestBlock: IOStdReqPtr;
  65.   HandlerStuff: Interrupt;
  66.   Escaped: BOOLEAN;     (* Disable can be quitted by pressing ESC *)
  67.  
  68. (*-------------------------------------------------------------------------*)
  69. (*                                                                         *)
  70. (*                          Input  Handler:                                *)
  71. (*                                                                         *)
  72. (*-------------------------------------------------------------------------*)
  73.  
  74. (* It's Variables are global (don't know if allocating them scratches      *)
  75. (* A0 or A1. Who knows ? Who's got a M2Amiga-Debugger ??? Or a even        *)
  76. (* a Disassembler, like TDI's ?¿?                                          *)
  77.  
  78. VAR
  79.   Ev, TraceEv: InputEventPtr;
  80.   Result: InputEventPtr;
  81.   Code: CARDINAL;
  82.  
  83. PROCEDURE MyHandler();
  84. (* That's my Input-Handler it receives 2 values, though in MODULA-2 it     *)
  85. (* looks like a Procedure receiving and returning nothing. Anyway, there's *)
  86. (* a Pointer returned:                                                     *)
  87. (* A0: Pointer to EventChain the Handler should handle with.               *)
  88. (* A1: This points to my MemEntries, i.e. contains HandlerStuff.date       *)
  89. (* D0: Will contain the new Pointer to Eventlist or NIL if none.           *)
  90.  
  91. (* $S- This avoids checking Stack size. This Procedure gets another Stack  *)
  92. (* than the main Programm !!                                               *)
  93.  
  94. CONST
  95.   ESC = 69;
  96.  
  97. BEGIN
  98.   Ev := ADDRESS(REG(8)); (* this gets InputEventList from A0 *)
  99.     (* A1 is ignored here 'cause there no memory needed *)
  100.   TraceEv := Ev;
  101.   WHILE TraceEv#NIL DO
  102.     WITH TraceEv^ DO
  103.       CASE class OF
  104.         rawkey:   LastRawKey := code;
  105.                   LastRawKeyTime := timeStamp;
  106.                   IF code=69 THEN Escaped := NOT(Escaped) END; |
  107.         rawmouse: Code := code;
  108.                   IF Code>127 THEN
  109.                     DEC(Code,128);
  110.                     IF    Code=lButton THEN LeftButtonRel   := timeStamp;
  111.                     ELSIF Code=mButton THEN MiddleButtonRel := timeStamp;
  112.                     ELSIF Code=rButton THEN RightButtonRel  := timeStamp END;
  113.                   ELSE
  114.                     IF    Code=lButton THEN LeftButton   := timeStamp;
  115.                     ELSIF Code=mButton THEN MiddleButton := timeStamp;
  116.                     ELSIF Code=rButton THEN RightButton  := timeStamp END;
  117.                   END;
  118.                   MouseX := MouseX + x;
  119.                   MouseY := MouseY + y;
  120.       ELSE
  121.       END;
  122.       LastTime := timeStamp;
  123.     END;
  124.     TraceEv := TraceEv^.nextEvent;
  125.   END;
  126.   IF Escaped THEN
  127.     SETREG(0,Ev);
  128.   ELSE
  129.     SETREG(0,NIL);
  130.   END;
  131. END MyHandler;
  132. (* that's it. I hope it to work !!! *)
  133.  
  134. (*-------------------------------------------------------------------------*)
  135. (*                                                                         *)
  136. (*                         DisableIntuition:                               *)
  137. (*                                                                         *)
  138. (*-------------------------------------------------------------------------*)
  139.  
  140. PROCEDURE DisableIntuition();
  141. (* Dies kann genausoleicht wie Forbid() aufgerufen werden                  *)
  142.  
  143. BEGIN
  144.   IF DisableIntuiCount=0 THEN
  145.     Escaped := FALSE;
  146.     WITH InputRequestBlock^ DO
  147.       command := addHandler;
  148.       data := ADR(HandlerStuff);
  149.     END;
  150.     DoIO(InputRequestBlock);
  151.   END;
  152.   INC(DisableIntuiCount);
  153. END DisableIntuition;
  154.  
  155. (*-------------------------------------------------------------------------*)
  156. (*                                                                         *)
  157. (*                         EnableIntuition:                                *)
  158. (*                                                                         *)
  159. (*-------------------------------------------------------------------------*)
  160.  
  161. PROCEDURE EnableIntuition();
  162.  
  163. BEGIN
  164.   DEC(DisableIntuiCount);
  165.   IF DisableIntuiCount=0 THEN
  166.     WITH InputRequestBlock^ DO
  167.       command := remHandler;
  168.       data := ADR(HandlerStuff);
  169.     END;
  170.     DoIO(InputRequestBlock);
  171.   END;
  172. END EnableIntuition;
  173.  
  174. (*-------------------------------------------------------------------------*)
  175. (*                                                                         *)
  176. (*                              TermProcedure:                             *)
  177. (*                                                                         *)
  178. (*-------------------------------------------------------------------------*)
  179.  
  180. PROCEDURE CleanUp();
  181.  
  182. BEGIN
  183.   DeleteStdIO(InputRequestBlock);
  184.   DeletePort(InputDevPort);
  185. END CleanUp;
  186.  
  187. (*-------------------------------------------------------------------------*)
  188. (*                                                                         *)
  189. (*           Main Programm (initialization, Printing and CleanUp)          *)
  190. (*                                                                         *)
  191. (*-------------------------------------------------------------------------*)
  192.  
  193. BEGIN
  194.   InputDevPort := CreatePort(NIL,0);
  195.   Assert(InputDevPort#NIL,ADR("CreatePort failed"));
  196.   InputRequestBlock := CreateStdIO(InputDevPort);
  197.   Assert(InputRequestBlock#NIL,ADR("CreateStdIO failed"));
  198.   WITH HandlerStuff DO
  199.     data := NIL;             (* pointer to it's data (I don't have any)  *)
  200.     code := ADR(MyHandler);  (* Thats my Handle-Procedure *)
  201.     node.pri := 52;
  202.   (* 52 to be higher than another Prg, that wants affekt Intuition *)
  203.   END;
  204.   OpenDevice(ADR(inputName),0,InputRequestBlock,LONGSET{});
  205.   TermProcedure(CleanUp);
  206. END ControlIntuition.
  207.